package com.woniuxy.gateway;

import cn.hutool.json.JSONUtil;
import com.woniuxy.gateway.util.Result;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 网关过滤器
 */
@Component
@Order(1)
public class AuthenticationFilter implements GlobalFilter {



    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //登录认证
        //响应
        System.out.println("lllllllllllllllllllll");
//        exchange.getResponse().getHeaders().setContentType(MediaType.APPLICATION_JSON);
//        Result<String> result = Result.getResult(String.class).setMsg("登录校验成功").setData("登录校验成功");
//        String s = JSONUtil.parse(result).toString();
//        return exchange.getResponse().writeWith(Mono.fromSupplier(()->{
//            return exchange.getResponse().bufferFactory().wrap(s.getBytes());
//        }));
        return chain.filter(exchange);
    }
}
